package com.example.xbrother.enums;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 物料分类枚举
 *
 * @author missjin
 */
@Slf4j
public enum MaterialTypeEnum {
    UPS("ups"),
    UPS_PARTS("ups配件"),
    AIR_CONDITIONER("空调"),
    air_conditioner_parts("空调配件");

    private final String name;

    public String getName() {
        return name;
    }

    MaterialTypeEnum(String name) {
        this.name = name;
    }

    /**
     * 获取列表
     */
    public static List<String> list() {
        return Arrays.stream(MaterialTypeEnum.values()).map(MaterialTypeEnum::getName).collect(Collectors.toList());
    }

    /**
     * 获取枚举值
     */
    public static MaterialTypeEnum of(String name) {
        return Arrays.stream(MaterialTypeEnum.values()).filter(x -> x.getName().equals(name)).findAny().orElse(null);
    }

    public static void main(String[] args) {
        log.info("list = {}", JSON.toJSONString(list()));

        log.info("name = {}", of("ups_a"));
    }
}
